# Maintainer: Oscar Fuentes <ofv@wanadoo.es>

_realname=asmjit
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.r392.g28c4d8c
pkgrel=3
pkgdesc="Machine code generation for C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="http://asmjit.com"
license=('spdx:Zlib')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "git")
_commit="28c4d8c528527141955006f09124ce672ddfbe3f"
source=(${_realname}-git::"git+https://github.com/asmjit/asmjit.git#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "${_realname}-git"
  echo '0.0.r'"$(git rev-list --count "${_commit}")"'.g'"$(git describe --all --long "${_commit}" | sed 's/^.*-g\(.*\)/\1/')"
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_CXX_STANDARD=11 \
    -DBUILD_SHARED_LIBS=ON \
    ../${_realname}-git

  cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" cmake --install .
}
